package com.mzj.saas.mservice.bill.controller;

import com.mzj.saas.commons.ApiData;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.bill.service.BillService;
import com.mzj.saas.mservice.bill.service.NewBillService;
import com.mzj.saas.mservice.bill.vo.BillSearchRequestVO;
import com.mzj.saas.mservice.bill.vo.CreateBillRequestParamVO;
import com.mzj.saas.mservice.bill.vo.EditBillRequestVO;
import com.mzj.saas.mservice.bill.vo.NewProjectVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公租房
 * @author shun
 * @createDate: 2022年7月5日 下午5:34:22
 * @version: 1.0
 *
 */
@Controller
@RequestMapping("/bill")
public class BillController {
    private static final Logger LOG = LoggerFactory.getLogger(BillController.class);
    @Autowired
    private BillService billService;
    @Autowired
    private NewBillService newBillService;

    /**
     * 费用列表-列表信息显示
     * @param accessToken 权限鉴定
     * @param pageNumber 当前页
     * @param pageSize 每页显示数量
     * @param type 类型标识 0全部账单 1未审核账单 2未缴费账单 3 已缴费账单
     * @param filter 费用列表筛查帮助类
     * @return
     */
    @PostMapping(value = "billListShow")
    @ResponseBody
    public ResultBean<Object> billListShow(@RequestHeader String accessToken,
                                           @RequestParam(defaultValue = "0") Integer pageNumber,
                                           @RequestParam(defaultValue = "10") Integer pageSize,
                                           @RequestParam(name = "type", defaultValue = "0") Integer type,
                                           BillSearchRequestVO filter) {
        return billService.billListShow(accessToken, pageNumber, pageSize, type, filter);
    }

    /*
     *费用列表-编辑账单
     */
    @PostMapping(value = "editBill")
    @ResponseBody
    public ResultBean<Object> editBill(@RequestHeader String accessToken, @RequestBody EditBillRequestVO vo) {
        return billService.editBill(accessToken, vo);
    }

    /**
     * 费用列表-审核
     * @param accessToken
     * @param ids
     */
    @PostMapping(value = "examineBill")
    @ResponseBody
    public ResultBean<Object> examineBill(@RequestHeader String accessToken, @RequestBody List<Long> ids
    ) {
        return billService.examineBill(accessToken, ids);
    }

    /**
     * 费用列表-设置
     * @param accessToken 权限鉴定
     * @param vo 编辑账单请求帮助类
     * @return
     */
    @PostMapping(value = "setupBill")
    @ResponseBody
    public ResultBean<Object> setupBill(@RequestHeader String accessToken, @RequestBody EditBillRequestVO vo
    ) {
        return billService.setupBill(accessToken, vo);
    }

    /**
     * 租金列表-列表信息展示
     * @param accessToken 权限鉴定
     * @param pageNumber 当前页
     * @param pageSize 每页显示数量
     * @param type type 0全部账单 1未缴费账单 2 已缴费账单
     * @param filter 费用列表筛查帮助类
     * @return
     */
    @PostMapping(value = "rentList")
    @ResponseBody
    public ResultBean<Object> rentList(@RequestHeader String accessToken,
                                       @RequestParam(defaultValue = "0") Integer pageNumber,
                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                       @RequestParam(name = "type", defaultValue = "0") Integer type,
                                       BillSearchRequestVO filter) {
        return billService.rentList(accessToken, pageNumber, pageSize, type, filter);
    }

    /**
     * 租金列表-审核
     * @param accessToken 权限鉴定
     * @param ids 审批账单id集合
     * @return
     */
    @PostMapping(value = "examineRentBill")
    @ResponseBody
    public ResultBean<Object> examineRentBill(@RequestHeader String accessToken, @RequestBody List<Long> ids
    ) {
        return billService.examineRentBill(accessToken, ids);
    }

    /**
     * 租金列表-设置
     * @param accessToken 权限鉴定
     * @param vo 编辑账单请求帮助类
     * @return
     */
    @PostMapping(value = "setupRentBill")
    @ResponseBody
    public ResultBean<Object> setupRentBill(@RequestHeader String accessToken, @RequestBody EditBillRequestVO vo
    ) {
        return billService.setupRentBill(accessToken, vo);
    }

    /**
     *账单生成-列表显示
     * @param accessToken 权限鉴定
     * @param pageNumber 当前页
     * @param pageSize 页数
     * @param id 账单id
     * @param communityId 所属小区id
     * @return
     */
    @PostMapping(value = "createBillList")
    @ResponseBody
    public ResultBean<Object> createBillList(@RequestHeader String accessToken,
                                             @RequestParam(defaultValue = "0") Integer pageNumber,
                                             @RequestParam(defaultValue = "10") Integer pageSize,
                                             @RequestParam(name = "id", required = false) String id,
                                             @RequestParam(name = "communityId", required = false) String communityId) {
        return billService.createBillList(accessToken, pageNumber, pageSize, id, communityId);
    }

    /**
     * 账单生成-生成账单
     * @param accessToken 权限鉴定
     * @param createBillRequestParamVO 创建账单对象
     * @return
     */
    @PostMapping(value = "createBill")
    @ResponseBody
    public ResultBean<Object> createBill(@RequestHeader String accessToken, @RequestBody CreateBillRequestParamVO createBillRequestParamVO) {
        return newBillService.createBill(accessToken, createBillRequestParamVO);
    }

    /**
     * 账单生成-编辑账单
     * @param accessToken 权限鉴定
     * @param createBillRequestParamVO 生成账单请求帮助类
     * @return
     */
    @PutMapping(value = "updateBill")
    @ResponseBody
    public ResultBean<Object> updateBill(@RequestHeader String accessToken, @RequestBody CreateBillRequestParamVO createBillRequestParamVO) {
        return newBillService.updateBill(accessToken, createBillRequestParamVO);
    }

    /*
     *账单生成-删除账单
     */
    @DeleteMapping(value = "deleteBill")
    @ResponseBody
    public ResultBean<Object> deleteBill(@RequestHeader String accessToken, String id){

        return newBillService.deleteBill(accessToken,id);
    }

    /**
     * 账单生成-账单详情
     * @param accessToken 权限鉴定
     * @param id 账单id
     * @return
     */
    @GetMapping(value = "billInfo")
    @ResponseBody
    public ResultBean<Object> billInfo(@RequestHeader String accessToken, String id){

        return newBillService.billInfo(accessToken,id);
    }

    /*
     *收费项目-添加更新
     */
    @PostMapping(value = "projectSave")
    @ResponseBody
    public ResultBean<Object> projectSave(@RequestHeader String accessToken,@RequestBody NewProjectVO vo) {
        return newBillService.projectSave(accessToken, vo);
    }

    /**
     * 收费项目-列表展示
     * @param accessToken 权限鉴定
     * @param pageNumber 当页面
     * @param pageSize 页数
     * @param vo 收费项目实体类
     * @return
     */
    @GetMapping(value = "projectList")
    @ResponseBody
    public ResultBean<ApiData<NewProjectVO>> projectList(@RequestHeader String accessToken,
                                                              @RequestParam(defaultValue = "0") Integer pageNumber,
                                                              @RequestParam(defaultValue = "10") Integer pageSize,
                                                              NewProjectVO vo) {
        return newBillService.projectList(accessToken, pageNumber, pageSize, vo);
    }

    /**
     * 收费项目-删除
     * @param accessToken 权限鉴定
     * @param id 项目id
     * @return
     */
    @DeleteMapping("/projectDelete")
    @ResponseBody
    public ResultBean<Object> projectDelete(@RequestHeader String accessToken, String id){

        return newBillService.projectDelete( accessToken, id);
    }

    /*
     *实现了点击账单生产按钮，查询收费项目
     */
    @GetMapping("/findByProjectList")
    @ResponseBody
    public ResultBean<Object> findByProjectList(@RequestHeader String accessToken){

        return newBillService.findByProjectList( accessToken);
    }

    /**
     * 查询账单范围下的房源数据
     * @param accessToken 权限鉴定
     * @param pageNumber 当前页
     * @param pageSize 页数
     * @param scope 账单范围选择[ 1物业、2小区、3楼栋、4单元、5房号]
     * @param chargeType 收费项目(1水费 2电费 3物业费 4宽带费 5电视费 6煤气费 7暖气费 8租金 9押金)
     * @param expenseId 收费项目id
     * @param communityId 所属小区
     * @param buildingNum 楼栋Id
     * @param unitId 单元Id
     * @param roomNumber 房号
     * @return
     */
    @GetMapping("/findByHouseInfo")
    @ResponseBody
    public ResultBean<Object> findByHouseInfo(@RequestHeader String accessToken,
                                              @RequestParam(defaultValue = "0") Integer pageNumber,
                                              @RequestParam(defaultValue = "10") Integer pageSize,
                                              Integer scope,Integer chargeType, String expenseId,String communityId, String buildingNum, String unitId, String roomNumber){

        return newBillService.findByHouseInfo( accessToken, pageNumber,pageSize,scope, chargeType, expenseId, communityId,  buildingNum,  unitId,  roomNumber);
    }

    /*
     *查询所有小区
     */
    @GetMapping(value = "communityList")
    @ResponseBody
    public ResultBean<Object> communityList(@RequestHeader String accessToken) {
        return billService.communityList(accessToken);
    }
}
